package com.zbp.web;


import com.zbp.config.exception.Result;
import com.zbp.config.taskExecutor.AsyncTaskService;
import com.zbp.model.vo.LoginVO;
import com.zbp.service.LoginService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * @author niuben
 */
@Slf4j
@RestController
@RequestMapping(value = "/auth")
@Api(tags = "登录接口")
public class LoginController {

    @Autowired
    private AsyncTaskService asyncTaskService;

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public Result<LoginVO> login(@RequestBody LoginVO loginVO) {
        LoginVO login = loginService.login(loginVO);
        return Result.success(login);
    }

    @GetMapping("/hello")
    public Result<Object> hello() throws Exception {
        List<Future<Object>> futureList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            futureList.add(asyncTaskService.subByAsync(i));
        }
        Future<Map> mapFuture = asyncTaskService.returnSubByAsync(futureList);
        return Result.success(mapFuture.get());
    }
}


